import { createStore, applyMiddleware, combineReducers } from 'redux'
import countReducer from './Count/redux/reducer' //引入reducer函数
import listReducer from './List/redux/reducer'
// redux调试工具使用的包
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk from 'redux-thunk'

// 注意: 实际开发的时候,为了避免代码冲突.每一程序员都会写自己的reducer函数.但是创建store时,只能传入一个reducer函数,所以就需要将多个reducer函数合并成一个
const rootReducer = combineReducers({
  zs: countReducer,
  ls: listReducer,
})
const store = createStore(
  rootReducer,
  // { xxx: 111, yyy: 222 }, 第二个参数是可选参数,可以用来初始化数据,但是不用
  composeWithDevTools(applyMiddleware(thunk))
)
store.subscribe(() => {
  console.log('store的数据改变了', store.getState())
})
export default store
